﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class AdminControl_ProDesDetails : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String proid = Request["proid"];
        ShoppingDataContext spdc = new ShoppingDataContext();

        var pronames = from p in spdc.PRODUCTs
                         where p.ProductID == proid
                         select p.ProName;
        if (pronames.Count() > 0)
            this.productname.Text = pronames.First();
        else return;

        var prodetails = from p in spdc.PRODUCT_DEs
                         where p.ProductID == proid
                         select p;


        DataTable dataTable = new DataTable();
        dataTable.Columns.Add("imageurl");
        dataTable.Columns.Add("size");
        dataTable.Columns.Add("color");
        dataTable.Columns.Add("number");
        dataTable.Columns.Add("price");
        dataTable.Columns.Add("discount");

        foreach (var detail in prodetails)
        {
            DataRow row = dataTable.NewRow();
            row["imageurl"] = detail.image;
            row["size"] = detail.Size;
            row["color"] = detail.Color;
            row["number"] = detail.number;
            row["price"] = Convert.ToInt32(detail.price);
            row["discount"] = detail.discount;
            dataTable.Rows.Add(row);
        }
        prodesdetails.DataSource = dataTable;
        prodesdetails.DataBind();

    }
    
    protected void DeleteClick(object sender, CommandEventArgs e)
    {
        ShoppingDataContext spdt = new ShoppingDataContext();
        var pro = from p in spdt.PRODUCT_DEs
                  where p.Product_DesID == e.CommandArgument.ToString()
                  select p;
        spdt.PRODUCT_DEs.DeleteOnSubmit(pro.First());
    }
    protected void UpdateClick(object sender, CommandEventArgs e)
    {
        ShoppingDataContext spdt = new ShoppingDataContext();
        var pro = from p in spdt.PRODUCT_DEs
                  where p.Product_DesID == e.CommandArgument.ToString()
                  select p;
        spdt.PRODUCT_DEs.DeleteOnSubmit(pro.First());
    }
}
